export default /* glsl */ `
  varying vec2 vUv;
  uniform vec4 dotColor;
  uniform vec2 repeat;
  vec2 lineThickness = vec2(1.0);
  vec2 lineOffset = vec2(0.0);
  const float czm_pixelRatio = 1.0;

  void main() {
    vec2 coord = vUv * repeat;
    // From Stefan Gustavson's Procedural Textures in GLSL in OpenGL Insights
    float b = smoothstep(0.2, 0.22, length(fract(coord) - 0.5));


    float scaledWidth = fract(coord.x - lineOffset.s);
    scaledWidth = abs(scaledWidth - floor(scaledWidth + 0.5));
    float scaledHeight = fract(coord.y - lineOffset.t);
    scaledHeight = abs(scaledHeight - floor(scaledHeight + 0.5));

    float value;
    #ifdef GL_OES_standard_derivatives
    // Fuzz Factor - Controls blurriness of lines
    const float fuzz = 1.2;
    vec2 thickness = (lineThickness * czm_pixelRatio) - 1.0;

    // From "3D Engine Design for Virtual Globes" by Cozzi and Ring, Listing 4.13.
    vec2 dx = abs(dFdx(vUv));
    vec2 dy = abs(dFdy(vUv));
    vec2 dF = vec2(max(dx.s, dy.s), max(dx.t, dy.t)) * repeat;
    value = min(
    smoothstep(dF.s * thickness.s, dF.s * (fuzz + thickness.s), scaledWidth),
    smoothstep(dF.t * thickness.t, dF.t * (fuzz + thickness.t), scaledHeight));
    #else
    // Fuzz Factor - Controls blurriness of lines
    const float fuzz = 0.05;

    vec2 range = 0.5 - (lineThickness * 0.05);
    value = min(
    1.0 - smoothstep(range.s, range.s + fuzz, scaledWidth),
    1.0 - smoothstep(range.t, range.t + fuzz, scaledHeight));
    #endif

    // vec4 color = mix(dotColor, vec4(0.0), b);
    // vec4 color = mix(dotColor, vec4(0.0), value);
    // vec4 color = min(max(val0, val1) * dotColor, mix(dotColor, vec4(0.0), b));
    vec4 color = mix(dotColor, vec4(0.0), max(b, value));
    gl_FragColor = LinearTosRGB(color);
  }
    `;
